//
//  PlaceCell.m
//  RoadLine
//
//  Created by dllo on 15/4/24.
//  Copyright (c) 2015年 RedFireNoodles. All rights reserved.
//
// 列表 自定义Cell
#import "PlaceCell.h"
#import "NightManager.h"

#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

@implementation PlaceCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        CGFloat width = [[UIScreen mainScreen] bounds].size.width;
        // cell的底层
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 5, width - 30 , HEIGHT * 1.6)];
        view.tag = 10000;
        //米色
        self.contentView.backgroundColor = [UIColor colorWithRed:250/255.0 green:245/255.0 blue:232/255.0 alpha:1];
        [self.contentView addSubview:view];
        view.layer.cornerRadius = 15;
        // 红色
        view.backgroundColor = [UIColor colorWithRed:246/255.0 green:85/255.0 blue:91/255.0 alpha:0.3];
        
        // 背景图片
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, width - 30 , HEIGHT * 1.6)];
        imageView.image = [UIImage imageNamed:@"backColorImage"];
        imageView.layer.cornerRadius = 8;
        imageView.clipsToBounds = YES;
        [view addSubview:imageView];
        [imageView release];
        
        // 背景图片上面的view
        UIView *viewUp = [[UIView alloc]initWithFrame:CGRectMake(0, 0, width - 30, HEIGHT * 1.6)];
//        viewUp.backgroundColor = [UIColor colorWithRed:249/255.0 green:242/255.0 blue:226/255.0 alpha:0.4];
        viewUp.tag = 10002;
        [imageView addSubview:viewUp];
        [viewUp release];
        
        
        // 地点名Label
        self.nameLbl = [[UILabel alloc] init];
        self.nameLbl.backgroundColor = [UIColor clearColor];
        self.nameLbl.textColor = [UIColor blackColor];
        [imageView addSubview:self.nameLbl];
        
        // xx喜欢
        self.wish_to_goLbl = [[UILabel alloc] init];
        [view addSubview:self.wish_to_goLbl];
        
        // xx去过
        self.visited_countLbl = [[UILabel alloc] init];
        [view addSubview:self.visited_countLbl];
        
        // 小图片
        self.destImgView = [[UIImageView alloc] init];
        [view addSubview:self.destImgView];
        self.destImgView.clipsToBounds = YES;
        self.destImgView.layer.cornerRadius = 10;
        
        [_destImgView release];
        [_visited_countLbl release];
        [_wish_to_goLbl release];
        [_nameLbl release];
        [view release];
//        [namebgView release];
    }
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    self.nameLbl.frame = CGRectMake(WIDTH / 6.25 + 20, 0, WIDTH / 2, 40);
    self.nameLbl.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
    self.wish_to_goLbl.frame = CGRectMake(WIDTH / 6.25 + 20, HEIGHT / 2, WIDTH / 3, 20);
    self.wish_to_goLbl.font = [UIFont fontWithName:@"Helvetica-Bold" size:12];
    self.visited_countLbl.frame = CGRectMake(WIDTH  * 2 / 3, HEIGHT / 2, WIDTH / 3, 20);
    self.visited_countLbl.font = [UIFont fontWithName:@"Helvetica-Bold" size:12];
    // 正方形  长宽一边高
    self.destImgView.frame = CGRectMake(10, 5, WIDTH / 6.25, WIDTH / 6.25);
    
    if ([Singleton shareSingleton].isNight) {
        [[Singleton shareSingleton] loadNightModeInfoFormDisk];
    }
}

// 白天
- (void)setLightDayModel {
    [NightManager setLabelColorWithLabel:self.nameLbl];
    [NightManager setLabelColorWithLabel:self.wish_to_goLbl];
    [NightManager setLabelColorWithLabel:self.visited_countLbl];
    self.contentView.backgroundColor = [UIColor colorWithRed:250/255.0 green:245/255.0 blue:232/255.0 alpha:1];
    UIView *view = [self.contentView viewWithTag:10000];
    view.backgroundColor = view.backgroundColor = [UIColor colorWithRed:246/255.0 green:85/255.0 blue:91/255.0 alpha:0.3];
    UIView *viewUp = [self.contentView viewWithTag:10002];
    viewUp.backgroundColor = [UIColor clearColor];
    UIView *namebgView = [view viewWithTag:10001];
    namebgView.backgroundColor = [UIColor colorWithRed:246/255.0 green:85/255.0 blue:91/255.0 alpha:0.8];
}
// 夜间
- (void)setNightDayModel {
    [NightManager setBackgroundColorWithView:self.contentView];
    [NightManager setLabelColorWithLabel:self.nameLbl];
    [NightManager setLabelColorWithLabel:self.wish_to_goLbl];
    [NightManager setLabelColorWithLabel:self.visited_countLbl];
    UIView *view = [self.contentView viewWithTag:10000];
    view.backgroundColor = view.backgroundColor = [UIColor colorWithRed:4/255.0 green:171/255.0 blue:165/255.0 alpha:0.5];
    UIView *viewUp = [self.contentView viewWithTag:10002];
    viewUp.backgroundColor = [UIColor colorWithRed:9/255.0 green:13/255.0 blue:29/255.0 alpha:0.4];
}

- (void)dealloc
{
    [_destImgView release];
    [_visited_countLbl release];
    [_wish_to_goLbl release];
    [_nameLbl release];
    [super dealloc];
}

@end
